package bb.lanxing.lib.devices.ble.device;

import android.content.Context;
import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.ble.dfu.DfuAdapter;
import bb.lanxing.lib.devices.core.dfu.IDfuAdapter;
import bb.lanxing.lib.devices.core.dfu.IDfuDevice;

public class SmartAssistDevice extends StandardCadenceDevice implements IDfuDevice {
    private IDfuAdapter mDfuAdapter;

    public SmartAssistDevice(Context context, SmartDevice smartDevice) {
        super(context, smartDevice);
    }

    @Override
    public void onServicesDiscovered() {
        super.onServicesDiscovered();
        IDfuAdapter iDfuAdapter = this.mDfuAdapter;
        if (iDfuAdapter != null) {
            iDfuAdapter.release();
            this.mDfuAdapter = null;
        }
    }

    @Override
    protected boolean shouldRefreshCache() {
        return this.mDfuAdapter != null;
    }

    @Override
    public IDfuAdapter getDfuAdapter() {
        if (this.mDfuAdapter == null) {
            this.mDfuAdapter = new DfuAdapter(this.mAppContext, this);
        }
        return this.mDfuAdapter;
    }

    @Override
    public boolean shouldAutoConnection() {
        return this.mDfuAdapter == null;
    }
}
